package com.chinaisafe.user.controller;

import com.chinaisafe.base.common.validated.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.chinaisafe.base.common.annotation.OperationLog;
import com.chinaisafe.base.common.enums.BusinessTypeEnum;
import com.chinaisafe.base.common.validated.AddGroup;
import com.chinaisafe.base.common.vo.Answer;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.chinaisafe.user.vo.request.SysLoginLogReqVO;
import com.chinaisafe.user.vo.response.SysLoginLogRespVO;
import org.springframework.validation.annotation.Validated;
import com.chinaisafe.user.service.SysLoginLogService;
import org.springframework.web.bind.annotation.RestController;

/**
 * SysLoginLogController
 * Description：登录日志接口层
 *
 * @author xuefu.shu
 * @date  2024-07-12 09:55:54
 */
@RestController
@RequestMapping("/sysLoginLog")
@Tag(name = "登录日志接口层", description = "登录日志接口层")
public class SysLoginLogController {

    @Autowired
    private SysLoginLogService sysLoginLogService;

    @GetMapping("/pageList")
    @Operation(summary = "获取分页登录日志列表", description = "获取登录日志分页列表")
    public Answer<IPage<SysLoginLogRespVO>> pageList(SysLoginLogReqVO sysLoginLogReqVO) {
        IPage<SysLoginLogRespVO> pageList = sysLoginLogService.getPageList(sysLoginLogReqVO);
        return Answer.success("获取成功", pageList);
    }

    @PostMapping()
    @Operation(summary = "新增登录日志", description = "新增登录日志")
    @OperationLog(title = "登录日志-新增", businessType = BusinessTypeEnum.INSERT)
    public Answer<SysLoginLogRespVO> add(@RequestBody @Validated(AddGroup.class) SysLoginLogReqVO sysLoginLogReqVO) {
        SysLoginLogRespVO sysLoginLogRespVO = sysLoginLogService.add(sysLoginLogReqVO);
        return Answer.success("保存成功", sysLoginLogRespVO);
    }

    @PutMapping()
    @Operation(summary = "根据id编辑登录日志", description = "根据id编辑登录日志")
    @OperationLog(title = "登录日志-根据id编辑", businessType = BusinessTypeEnum.UPDATE)
    public Answer<SysLoginLogRespVO> update(@RequestBody @Validated(UpdateGroup.class) SysLoginLogReqVO sysLoginLogReqVO) {
        SysLoginLogRespVO sysLoginLogRespVO = sysLoginLogService.update(sysLoginLogReqVO);
        return Answer.success("修改成功", sysLoginLogRespVO);
    }

    @GetMapping("/{sysLoginLogId}")
    @Operation(summary = "根据id获取登录日志", description = "根据id获取登录日志")
    public Answer<SysLoginLogRespVO> getDetailById(@PathVariable Long sysLoginLogId) {
        SysLoginLogRespVO sysLoginLogRespVO = sysLoginLogService.getDetailById(sysLoginLogId);
        return Answer.success("获取成功", sysLoginLogRespVO);
    }

    @DeleteMapping()
    @Operation(summary = "根据id删除登录日志", description = "根据id删除登录日志")
    @OperationLog(title = "登录日志-根据id删除", businessType = BusinessTypeEnum.DELETE)
    public Answer<Void> deleteByIds(@RequestParam("ids") Long[] ids) {
        sysLoginLogService.deleteByIds(ids);
        return Answer.success("删除成功");
    }
}

